package org.itstack.demo.design.impl;

import org.itstack.demo.design.ICouponDiscount;

import java.math.BigDecimal;

/**
 * @Author: fanYuLe
 * @CreateTime: 2023-12-29  09:30
 * @Description: 直减
 */
public class ZJCouponDiscount implements ICouponDiscount<Double> {
    /**
     * 直减计算
     * 1.使用商品价格-优惠价格
     * 2.最低支付1元
     * @param couponInfo 券折扣信息：直减、满减、折扣、N元购
     * @param skuPrice 商品金额
     * @return
     */
    @Override
    public BigDecimal discountAmount(Double couponInfo, BigDecimal skuPrice) {
        BigDecimal discountAmount = skuPrice.subtract(new BigDecimal(couponInfo));
        if(discountAmount.compareTo(BigDecimal.ZERO)<1){
            return BigDecimal.ONE;
        }
        return discountAmount;
    }
}
